package system.api;

import system.impl.CommandLineClient;
import system.impl.CommandLineClientNavigator;
import system.impl.SingleRequestClient;
import system.impl.SingleRequestClientNavigator;
import system.impl.SwingClient;
import system.impl.SwingClientNavigator;
import client.Client;
import client.ClientNavigator;

	public abstract ClientNavigator createNavigator(ClientNavigator navigator, Object user);

	public Client createClient(ClientNavigator navigator, Object user) throws Exception {
		navigator.clearCommands();
		Client client = null;
		if(navigator instanceof SingleRequestClientNavigator)
			client = new SingleRequestClient((SingleRequestClientNavigator) createNavigator(navigator, user));
		else if(navigator instanceof SwingClientNavigator)
			client = new SwingClient((SwingClientNavigator) createNavigator(navigator, user));
		else if(navigator instanceof CommandLineClientNavigator)
			client = new CommandLineClient((CommandLineClientNavigator) createNavigator(navigator, user));
		else {
			throw new Exception("Unknown navigator type");
		}
		return client;
		
		
	}
	
	public Client createClient(ClientNavigator navigator) throws Exception {
		return createClient(navigator, null);
	}
	
	public Client createClient(Class<? extends ClientNavigator> navigatorClass, Object user) throws Exception {
		if(navigatorClass.equals(SingleRequestClientNavigator.class))
			return createClient(new SingleRequestClientNavigator(), user);
		if(navigatorClass.equals(SwingClientNavigator.class))
			return createClient(new SwingClientNavigator(), user);
		if(navigatorClass.equals(CommandLineClientNavigator.class))
			return createClient(new CommandLineClientNavigator(), user);
		return null;
	}
	
	public Client createClient(Class<? extends ClientNavigator> navigatorClass) throws Exception {
		return createClient(navigatorClass, null);
	}

}
